package com.example.klaraservice.controller;

import com.example.klaraservice.pojo.OrderItem;
import com.example.klaraservice.service.OrderItemService;
import com.example.klaraservice.vo.R;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author : Glacialerisa
 * @date : 2023/6/13 23:13
 * @desc :
 */
@Api(tags = "订单子项")
@RestController
@RequestMapping("/api/orderItem")
public class OrderItemController {
    //TODO 添加新的订单子项
    @Resource
    private OrderItemService orderItemService;
    @PostMapping("/addOrderItem")
    public R addOrderItem(@RequestBody List<OrderItem> orderItemList, @RequestParam int ordersId){
        boolean result=false;
        for (OrderItem o:orderItemList
             ) {
             result = orderItemService.addOrderItem(o, ordersId);
             if (!result){
                 break;
             }
        }
        if (result){
            return R.ok();
        }else {
            return R.error();
        }
    }
    //TODO 获取某个订单号下的所有订单子项

}
